****FIGURE 3****

cap erase "$data_dir/shapefiles/world_shp.dta"
cap erase "$data_dir/shapefiles/world_shp2.dta"
cap erase "$data_dir/shapefiles/world.dta"

graph set window fontface "Palatino"

//--------------------------------------------------------
//Create spatial dataset for choropleth map
//--------------------------------------------------------

cd "$data_dir/shapefiles"

clear
spshape2dta "$data_dir/shapefiles/World_Countries_Generalized/World_Countries_Generalized.shp", replace saving(world)

clear
use "$data_dir/shapefiles/world_shp.dta"

geo2xy _Y _X, proj(web_mercator) replace

save "$data_dir/shapefiles/world_shp2.dta", replace

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/shapefiles/world.dta"

rename AFF_ISO S009

drop if COUNTRY=="Canarias"
drop if COUNTRY=="Azores"
drop if COUNTRY=="Madeira"

drop if S009=="BQ"
drop if S009=="TF"
drop if S009=="AQ"

merge m:m S009 using "$main_dir/data/raw/countrycodes.dta", keepusing(ccode)
drop if _merge==2
drop _merge

drop if COUNTRYAFF=="Australia" & COUNTRY!="Australia"
drop if COUNTRY=="Faroe Islands"
drop if COUNTRY=="Antarctica"
drop if COUNTRYAFF=="France" & COUNTRY!="France"
drop if COUNTRYAFF=="United Kingdom" & COUNTRY!="United Kingdom"
drop if COUNTRYAFF=="Netherlands" & COUNTRY!="Netherlands"
drop if COUNTRYAFF=="Norway" & COUNTRY!="Norway"
drop if COUNTRYAFF=="New Zealand" & COUNTRY!="New Zealand"
drop if COUNTRYAFF=="United States" & COUNTRY!="United States"

merge m:1 ccode using "$data_dir/clean/harmonized_pooled_averages.dta", keepusing(trust_govt_wo)

format trust_govt_wo %5.0g

//--------------------------------------------------------
//Create Figure 3
//--------------------------------------------------------

cd "$main_dir/output/figures/main"

spmap trust_govt_wo using "$data_dir/shapefiles/world_shp2.dta", id(_ID) ///
     clnum(5) ///
     fcolor(Greens)  ///
	 ndsize(thin) ///
     legstyle(2) legend(pos(7) size(2.8) region(fcolor(gs15)))   ///
     ocolor(black ..) osize(0.05 ..)
graph export "figure_3.png", replace
graph export "figure_3.tif", replace as(tif) width(3600)
